import { ref, reactive, onMounted, watch } from 'vue'
import { getEInquiryList } from '/@/api/expert/list'
import { geGaugetype, geMeasureList } from '/@/api/home/home'
import { getList } from '/@/api/article/article'

//心理专家
export function useExpert() {
  const expertList: any[] = reactive([])

  onMounted(async () => {
    getEInquiryList(1, 100, { state: 1 }).then((res) => {
      const data = res.data.data.records
      data.forEach((item: any[]) => {
        expertList.push(item)
      })
    })
  })

  return {
    expertList,
  }
}

//测试与专项测评
export function useEvaluation(ctr_user: Record<string, any>) {
  let specialList = ref<Array<any>>([])

  let projectType = reactive({
    obj: {} as any,
  })

  watch(
    () => projectType.obj,
    () => {
      const tenantId = ctr_user && ctr_user.tenantId
      geMeasureList(1, 100, {
        gaugeTypeId: projectType.obj.projectGaugeTypeId,
        tenantId: tenantId,
        status: 1,
      }).then((res) => {
        specialList.value = res.data.data.records
      })
    }
  )

  const categoryOptions = ref<any[]>([])
  geGaugetype().then((res) => {
    const data: any[] = res.data.data
    categoryOptions.value = data
    data.forEach((item) => {
      if (item.typeName == '专项测试') projectType.obj = item
    })
  })

  return {
    specialList,
    categoryOptions,
  }
}

//文章
export function useArticle() {
  const articleList = ref<any[]>([])
  getList(1, 3, {}).then((res) => {
    articleList.value = res.data.data.records
  })

  return {
    articleList,
  }
}
